package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.OrderReportVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: HuoXu
 * @Date: 2023/08/31/11:16
 * @Description: 快乐跳跳虎
 */
@Mapper
public interface OrderMapper {


    void setOrder(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 删除订单表的数据
     * @param id
     */
    @Delete("delete from orders where id=#{id}")
    void cancelOrder(Long id);

    /**
     * 查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    @Select("select * from orders where user_id=#{userId} order by order_time desc")
    Page<Orders> queryByPage(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 处理超时订单,根据订单支付状态和订单下单时间进行判断
     * @return
     */
    @Select("select * from orders where status=#{status} and order_time < #{ordertime}")
    List<Orders> selectByStatusAndOrderTime(Integer status, LocalDateTime ordertime);
    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 获取不同状态的订单
     * @param toBeConfirmed
     * @return
     */
    Integer queryByBeConfirmed(Integer toBeConfirmed);

    Integer queryByBeDelivered(Integer confirmed);

    Integer queryBydeliveryInProgress(Integer deliveryInProgress);

    /**
     * 接单
     * @param ordersConfirmDTO
     */
    @Update("update orders set status=3 where id=#{id}")
    void receivingOrders(OrdersConfirmDTO ordersConfirmDTO);

    /**
     * 订单统计
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 统计营业额
     * @param beginTime
     * @param endTime
     * @param completed
     * @return
     */
    Double turnoverStatistics(@Param("beginTime") LocalDateTime beginTime,
                              @Param("endTime")LocalDateTime endTime,
                              @Param("completed")Integer completed);

    List<GoodsSalesDTO> topTen(LocalDateTime beginTime, LocalDateTime endTime);
}
